using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Baula.Testing.Common.Tests
{
    [TestClass]
    public class AssertExtensionsTestsForString_AssertEqualsIgnoringTrailingNewLine_Passing
    {
        [TestMethod]
        public void Null_Null()
        {
            AssertBothWays(null, null);
        }

        [TestMethod]
        public void Empty_Empty()
        {
            AssertBothWays(string.Empty, string.Empty);
        }

        [TestMethod]
        public void Same_SingleLine()
        {
            AssertBothWays("Some content", "Some content");
        }

        [TestMethod]
        public void Same_MultipleEmptyLines()
        {
            AssertBothWays("\r\n\r\n\r\n",
                           "\r\n\r\n\r\n");
        }

        [TestMethod]
        public void Empty_NewLine()
        {
            AssertBothWays(string.Empty, "\r\n");
        }

        [TestMethod]
        public void TwoNonEmptyLines_SamePlusOneNewLine()
        {
            AssertBothWays("Line 1\r\nLine2",
                           "Line 1\r\nLine2\r\n");
        }

        private void AssertBothWays(string s1, string s2)
        {
            AssertPass(s1, s2);
            AssertPass(s2, s1);
        }

        private void AssertPass(string s1, string s2)
        {
            s1.AssertEqualsIgnoringTrailingNewLine(s2);
        }
    }

    [TestClass]
    public class AssertExtensionsTestsForString_AssertEqualsIgnoringTrailingNewLine_Failing
    {
        [TestMethod]
        public void Null_Empty()
        {
            AssertBothWays(null, string.Empty);
        }

        [TestMethod]
        public void Null_NonEmpty()
        {
            AssertBothWays(null, "Some content");
        }

        [TestMethod]
        public void Empty_NonEmpty()
        {
            AssertBothWays(string.Empty, "Some content");
        }

        [TestMethod]
        public void TwoNonEmptyLines_SamePlusTwoNewLines()
        {
            AssertBothWays("Line 1\r\nLine2",
                           "Line 1\r\nLine2\r\n\r\n");
        }

        private void AssertBothWays(string s1, string s2)
        {
            AssertFail(s1, s2);
            AssertFail(s2, s1);
        }

        private void AssertFail(string s1, string s2)
        {
            ExceptionAssert.Expect<AssertFailedException>(
                () => s1.AssertEqualsIgnoringTrailingNewLine(s2)
                );
        }
    }
}